package com.resou.reader.bookdetail.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.resou.reader.R;
import com.resou.reader.utils.log.DLog;

/**
 * Created by ${Garrett} on 2018/9/5.
 * Contact me krouky@outlook.com
 */
public class ReplyCommentPopDialog extends PopupWindow implements View.OnClickListener {

    public static final int TYPE_REPLY = 0;
    public static final int TYPE_COPY = 1;
    public static final int TYPE_REPORT = 2;

    private OnClickCallback callback;

    public ReplyCommentPopDialog(Context context, OnClickCallback callback) {
        this.callback = callback;
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setOutsideTouchable(true);
        setFocusable(true);
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View contentView = LayoutInflater.from(context).inflate(R.layout.reply_comment_layout, null, false);
        setContentView(contentView);

        contentView.findViewById(R.id.reply_comment).setOnClickListener(this);
        contentView.findViewById(R.id.copy_comment).setOnClickListener(this);
        contentView.findViewById(R.id.report_comment).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.reply_comment:
                DLog.d(ReplyCommentPopDialog.class.getSimpleName(), "reply_comment!");
                callback.onClick(TYPE_REPLY);
                break;
            case R.id.copy_comment:
                callback.onClick(TYPE_COPY);
                break;
            case R.id.report_comment:
                callback.onClick(TYPE_REPORT);
                break;
        }
        dismiss();
    }

    public interface OnClickCallback {
        void onClick(int type);
    }
}
